package com.lk.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.lk.entity.LinkMan;
import com.lk.util.DBHelp;
import com.lk.util.RowMapper;

public class ContactDao {
	DBHelp<LinkMan> db = new DBHelp<LinkMan>();
	
	public void save(LinkMan lm){
		String sql = "insert into t_linkman(id,l_name,l_company,l_telephone,l_phone,l_email,l_address,l_home_html,l_blog,l_describle,l_createTime,t_project_id) values(?,?,?,?,?,?,?,?,?,?,?,?)";
		db.executeSQL(sql,lm.getL_id(),lm.getL_name(),lm.getL_company(),lm.getL_telephone(),lm.getL_phone(),lm.getL_email(),lm.getL_address(),lm.getL_home_html(),lm.getL_blog(),lm.getL_describle(),lm.getL_createTime(),lm.getT_project_id());
	}
	
	public List<LinkMan> findAll(String t_project_id){
		String sql = "select id,l_name,l_company,l_telephone,l_phone,l_email,l_address,l_home_html,l_blog,l_describle,l_createTime,t_project_id from t_linkman where t_project_id = ?";
		return db.executeSQLForList(sql, new LinkmanRowMapper(), t_project_id);
	}
	
	public LinkMan findById(String l_id){
		String sql = "select id,l_name,l_company,l_telephone,l_phone,l_email,l_address,l_home_html,l_blog,l_describle,l_createTime,t_project_id from t_linkman where id = ?";
		return db.executeSQLForObject(sql, new LinkmanRowMapper(), l_id);
	}
	
	
	
	public class LinkmanRowMapper implements RowMapper<LinkMan>{
		public LinkMan rowmapper(ResultSet rs) throws SQLException {
			LinkMan lm = new LinkMan();
			lm.setL_id(rs.getString("id"));
			lm.setL_name(rs.getString("l_name"));
			lm.setL_telephone(rs.getString("l_telephone"));
			lm.setL_address(rs.getString("l_address"));
			lm.setL_company(rs.getString("l_company"));
			lm.setL_phone(rs.getString("l_phone"));
			lm.setL_email(rs.getString("l_email"));
			lm.setL_blog(rs.getString("l_blog"));
			lm.setL_home_html(rs.getString("l_home_html"));
			lm.setL_createTime(rs.getString("l_createTime"));
			lm.setL_describle(rs.getString("l_describle"));
			lm.setT_project_id(rs.getString("t_project_id"));
			return lm;
		}
	} 
}
